//
//  SESettingController.m
//  kuaiyi
//
//  Created by Alphts on 16/7/5.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SESettingController.h"
#import "FeedBackController.h"
#import "SEHomeController.h"
#import "SELeftController.h"

#define kUserName @"username"

@interface SESettingController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation SESettingController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self setupUI];

}

-(void)setupUI{
    
    UITableView *table = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    
    table.tableFooterView = [[UIView alloc]init];
    
    table.dataSource = self;
    
    table.delegate = self;
    
    [table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"identifier"];
    
    [self.view addSubview:table];
    
}

#pragma mark -tableViewDelegate
//定义cell的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *array = @[@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户"];
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier" forIndexPath:indexPath];
    
    cell.textLabel.text = array[indexPath.row];
    
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

//点击相应的cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        FeedBackController *feedVc = [[FeedBackController alloc] init];

        [self.navigationController pushViewController:feedVc animated:YES];
    }else if (indexPath.row == 3){
        
        UIAlertController *logOff = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您确定要注销吗？" preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            //清除密码和用户名
            [MLDefaults setObject:@"" forKey:kUserName];
            [MLDefaults setObject:@"" forKey:@"password"];
            
            //清除病例管理的记录
            [NSKeyedArchiver archiveRootObject:@[] toFile:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"XGIllCaseReprot.data"]];
            
            [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
            
            [SVProgressHUD showSuccessWithStatus:@"注销成功"];
            
            [self performSelector:@selector(dismiss) withObject:nil afterDelay:2];
            
            if (_returnBackBlock) {
                _returnBackBlock();
            }
            
        }];
        
        UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        
        [logOff addAction:sure];
        [logOff addAction:cancle];
        
        [self presentViewController:logOff animated:YES completion:nil];
        
    }
}

#pragma mark -消退提示框回到主界面
-(void)dismiss{
    
    [SVProgressHUD dismiss];
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
